package pta;



/**
 * @author： li
 * @date： 2022-04-06 09:15
 * @version 1.0
 */
import java.io.*;
import java.util.Scanner;
public class 矩阵a乘b {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(new InputStreamReader(System.in));
        in.nextToken();
        int r1 = (int)in.nval;
        in.nextToken();
        int c1 = (int)in.nval;
        int[][] a = new int[r1][c1];
        for(int i=0;i<r1;i++)
            for(int j=0;j<c1;j++){
                in.nextToken();
                a[i][j] =(int)in.nval;
            }
        in.nextToken();
        int r2 = (int)in.nval;
        in.nextToken();
        int c2 = (int)in.nval;
        int[][] b = new int[r2][c2];
        for(int i=0;i<r2;i++)
            for(int j=0;j<c2;j++){
                in.nextToken();
                b[i][j]=(int)in.nval;
            }
            StringBuffer ans = new StringBuffer();
        if(c1==r2){
            ans.append(r1).append(" ").append(c2).append("\n");
            for(int i=0;i<r1;i++){
                for(int j=0;j<c2;j++){
                    long sum=0;
                    for(int k=0;k<c1;k++){
                        sum+=a[i][k]*b[k][j];
                    }
                    ans.append(ans);
                    if(j<c2-1)
                        ans.append(" ");
                }
                ans.append("\n");
            }
        }else {
            out.write("Error:"+" "+c1+" "+"!= "+r2);
        }
        out.write(ans.toString());
        out.flush();
    }
}
